

package entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *
 * @author Elise
 */
@NamedQuery(name="findByName",
            query= 
                "SELECT c" +
                " FROM Customer c" +
                " WHERE LOWER(c.firstName) = LOWER(:entry)" +
                " OR LOWER(c.lastName) = LOWER(:entry)"
                )

@Entity
public class Customer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    private Long id;

    //Attributes//////////////////////////////////////
    private String firstName;
    private String lastName;
    private String address;
    private int phoneNumber;

    //Constructors////////////////////////////////////
    public Customer(String f, String l, String addr, int ph){
        this.firstName = f;
        this.lastName = l;
        this.address = addr;
        this.phoneNumber = ph;
    }

    public Customer(String f, String l, String addr){
        this.lastName = f;
        this.firstName = l;
        this.address = addr;
    }

    public Customer(String f, String l){
        this.firstName = f;
        this.lastName = l;
    }

    public Customer(){}

    //Accessor methods////////////////////////////////
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    public String getFirstName(){return firstName;}
    public void setFirstName(String f){this.firstName = f;}
    public String getLastName(){return lastName;}
    public void setLastName(String l){this.lastName = l;}
    public String getAddress(){return address;}
    public void setAddress(String addr){this.address = addr;}
    public int getPhoneNumber(){return phoneNumber;}
    public void setPhoneNumber(int ph){this.phoneNumber = ph;}

    //Other Methods//////////////////////////////////
    public String getName(){return firstName + " " + lastName;}
    //Overrides//////////////////////////////////////
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Customer[id=" + id + "]";
    }

}
